package jp.co.ikd.util;

import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;

import org.junit.Test;

public class DecimalTest {

	@Test
	public void testAdd() {
		BigDecimal bdecString1 = new BigDecimal("123.456");
		BigDecimal bdecString2 = new BigDecimal("12.34500");

		//TODO:スケールについては取り除くメソッドがあればよい？
		assertEquals(new BigDecimal("135.80100"), Decimal.add(bdecString1, bdecString2));
	}

	@Test
	public void testSubstract() {
		BigDecimal bdecString1 = new BigDecimal("123.456");
		BigDecimal bdecString2 = new BigDecimal("12.34500");

		//TODO:スケールについては取り除くメソッドがあればよい？
		assertEquals(new BigDecimal("111.11100"), Decimal.subtract(bdecString1, bdecString2));
	}

	@Test
	public void testMultiply() {
		BigDecimal bdecString1 = new BigDecimal("123.456");
		BigDecimal bdecString2 = new BigDecimal("12.34500");

		//TODO:スケールについては取り除くメソッドがあればよい？
		assertEquals(new BigDecimal("1524.06432000"), Decimal.multiply(bdecString1, bdecString2));
	}

	@Test
	public void testDivide() {
		BigDecimal bdecString1 = new BigDecimal("123.456");
		BigDecimal bdecString2 = new BigDecimal("12.34500");

		System.out.println("bdecString1:" + bdecString1);
		System.out.println("bdecString2:" + bdecString2);

		// TODO:丸めモードは何が適切か？
		System.out.println(bdecString1.divide(bdecString2, BigDecimal.ROUND_HALF_DOWN));

		System.out.println("bdecString1:" + bdecString1);
		System.out.println("bdecString2:" + bdecString2);
	}

	@Test
	public void testFormat(){
		BigDecimal bdecString1 = new BigDecimal("123456.789");
		BigDecimal bdecString2 = new BigDecimal("123456.78900");
		assertEquals("123,456", Decimal.format(bdecString1,0, true, false, false));
		assertEquals("123,456.7", Decimal.format(bdecString1,1, true, false, false));
		assertEquals("123,456.78", Decimal.format(bdecString1,2, true, false, false));
		assertEquals("123,456.789", Decimal.format(bdecString1,3, true, false, false));
		assertEquals("123,456.789", Decimal.format(bdecString1,4, true, false, false));

		assertEquals("￥123,456", Decimal.format(bdecString1,0, true, true, false));
		assertEquals("￥123,456.7", Decimal.format(bdecString1,1, true, true, false));
		assertEquals("￥123,456.78", Decimal.format(bdecString1,2, true, true, false));

		assertEquals("123,456%", Decimal.format(bdecString1,0, true, false, true));
	}
}
